/*
 * Atomic.h
 *
 *	Author: stravant
 *	Description:
 *		
 */

#ifndef ATOMIC_H_
#define ATOMIC_H_

#include <boost/interprocess/detail/atomic.hpp>

#include "../core/BasicTypes.h"

class AtomicUInt32 {
public:
	AtomicUInt32(): mNum(0) {}
	AtomicUInt32(uint32 n): mNum(n) {}
	AtomicUInt32(const AtomicUInt32& other): mNum(other.get()) {}

	uint32 get() const {
		return boost::interprocess::detail::atomic_read32(const_cast<uint32*>(&mNum));
	}
	void set(uint32 num) {
		boost::interprocess::detail::atomic_write32(const_cast<uint32*>(&mNum), num);
	}
	uint32 inc() {
		return boost::interprocess::detail::atomic_inc32(&mNum);
	}
	uint32 dec() {
		return boost::interprocess::detail::atomic_dec32(&mNum);
	}
private:
	volatile uint32 mNum;
};

#endif /* ATOMIC_H_ */
